<?php 
namespace app\home\model;
use think\Model;
use app\home\model\Cate;
/**
* 
*/
class Article extends Model
{
	
	public function getAllArticles($cateid){
		$cate=new Category();
		$CateAllID=$cate->getchilrenid($cateid);//当前栏目下面所有之栏目的id及自己的id
		
		$artRes=db('article')->where("cateid IN($CateAllID)")->order('aid desc')->paginate(9);
		
		return $artRes;
	}
	// 推荐文章
	public function getRecArt(){
        $recArt=$this->where('rec','=',1)->field('aid,title,thumb')->order('aid desc')->limit(4)->select();
        return $recArt;
    }
    // 最新文章
     public function getNewArticle(){
        $newArtiecleRes=db('article')->field('a.aid,a.title,a.desc,a.thumb,a.create_time,c.catename')->alias('a')->join('category c','a.cateid=c.cid')->order('a.aid desc')->limit(9)->select();
        return $newArtiecleRes;
    }
      public function getNewArticleTitle(){
        $newArtiecleTitle=db('article')->field('a.aid,a.title,a.desc,a.thumb,a.create_time,c.catename')->alias('a')->join('category c','a.cateid=c.cid')->order('a.aid desc')->limit(1)->select();
        return $newArtiecleTitle;
    }
}